package com.xyu.gulimall.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class RoutesConfig {
    //renren-fast路由
    @Bean
    public RouteLocator renren_fast(RouteLocatorBuilder builder){
        return builder
                .routes()
                .route("renren-fast",r -> r.path("/api/**")
                        .filters(f -> f.rewritePath("/api/?(?<segment>.*)","/renren-fast/$\\{segment}"))
                        //.uri("http://localhost:8080"))
                        .uri("lb://renren-fast"))
                .build();
    }
    //商品服务路由
    @Bean
    public RouteLocator gulimall_product(RouteLocatorBuilder builder){
        return builder
                .routes()
                .route("gulimallProduct",r -> r.path("/api/product/**")
                        .filters(f -> f.rewritePath("/api/?(?<segment>/?.*)","/$\\{segment}"))
                        //.uri("http://localhost:8080"))
                        .uri("lb://gulimall-product"))
                .build();
    }
}
